﻿#region license
// CopyRight (c) 2009-2010 HangJing Teconology. All Rights Reserved.
// Function :礼品信息详细
// Created by tuhui at 2010-6-24 16:28:14.
// E-Mail: tuhui@ihangjing.com
#endregion
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using Hangjing.SQLServerDAL;
using Hangjing.Model;
using Hangjing.Common;
using Hangjing.Cache;
using Hangjing.Control;

/// <summary>
/// 装备信息
/// </summary>
public partial class qy_54tss_Admin_deviceDetail : System.Web.UI.Page
{
    Devices dal = new Devices();
    protected void Page_Load(object sender, EventArgs e)
    {
        ValidatorSet validator = new ValidatorSet("Admin");
        validator.SetValidator();
        if (!Page.IsPostBack)
        {
            WebUtility.SetDDLCity(tbcityid);

            WebUtility.BindList("id", "classname", CacheHelper.GetDeviceSorts().ToList(), tbsortid);
            WebUtility.BindList("title", "title", CacheHelper.GetFreeshifts().ToList(), tbunit);


            if (HjNetHelper.GetQueryString("id") == "")
            {
                pageType.Text = "添加物料";
            }
            else
            {
                pageType.Text = "编辑物料";
                int id = HjNetHelper.GetQueryInt("id", 0);
                DevicesInfo info = dal.GetModel(id);

                WebUtility.SelectValue(tbcityid, info.cityid);
                WebUtility.SelectValue(tbsortid, info.sortid);


                tbdevNO.Text = info.devNO;
                tbtitle.Text = info.title;
                WebUtility.SelectValue(tbunit, info.unit);
                tbprice.Text = info.price.ToString();
                tbintro.Text = info.intro;

            }
        }
    }

    protected void btSave_Click(object sender, EventArgs e)
    {
        DevicesInfo info = new DevicesInfo();
        info.dId = HjNetHelper.GetQueryInt("id", 0);
        if (info.dId > 0)
        {
            info = dal.GetModel(info.dId);
        }
        else
        {
            info.stock = 0;
            info.addtime = DateTime.Now;
            info.delflag = 0;
            info.deluser = "";
            info.deltime = TimeHelper.getDefaultTime();

        }

        info.cityid = WebUtility.InputText(tbcityid.SelectedValue, true);
        info.cityname = WebUtility.InputText(tbcityid.SelectedItem.Text);
        info.sortid = WebUtility.InputText(tbsortid.SelectedValue, true);
        info.devNO = WebUtility.InputText(tbdevNO.Text);
        info.title = WebUtility.InputText(tbtitle.Text);
        info.unit = WebUtility.InputText(tbunit.Text);
        info.price = WebUtility.InputText(tbprice.Text, 'c');
        info.pri = 0;
        info.intro = WebUtility.InputText(tbintro.Text);
        info.admin = UserHelp.GetAdmin().ID;
        info.reveint1 = "0";
        info.reveint2 = 0;
        info.reveint3 = 0;
        info.reveint4 = 0; ;
        info.revevar1 = "";
        info.revevar2 = "";
        info.revevar3 = "";
        info.revevar4 = "";
        info.revedate1 = TimeHelper.getDefaultTime();
        info.revedate2 = TimeHelper.getDefaultTime();
        info.revefloat1 = 0;
        info.revefloat2 = 0;

        if (info.dId == 0)
        {
            string sqls = "devNO='" + info.devNO + "'";
            if (dal.GetCount(sqls) > 0)
            {
                AlertScript.RegScript(this.Page, UpdatePanel1, "alert('相同编号的物料已经存在，请重新输入','text:新增商家信息失败，登录名已存在!','250','150','true','3000','true','text');init();");
                return;
            }


            if (dal.Add(info) > 0)
            {
                AlertScript.RegScript(this.Page, this.UpdatePanel1, "showMessage('新增成功','success','true',5);");
            }
            else
            {
                AlertScript.RegScript(this.Page, this.UpdatePanel1, "showMessage('新增失败','error','true',5);");
            }
        }
        else
        {
            string sqls = "devNO='" + info.devNO + "'  and did <> " + info.dId;
            if (dal.GetCount(sqls) > 0)
            {
                AlertScript.RegScript(this.Page, UpdatePanel1, "alert('相同编号的物料已经存在，请重新输入','text:新增商家信息失败，登录名已存在!','250','150','true','3000','true','text');init();");
                return;
            }

            if (dal.Update(info) > 0)
            {
                AlertScript.RegScript(this.Page, this.UpdatePanel1, "showMessage('编辑成功','success','true',5);");
            }
            else
            {
                AlertScript.RegScript(this.Page, this.UpdatePanel1, "showMessage('编辑失败','error','true',5);");
            }
        }


    }
}
